﻿<?php

class ServiceAction extends Action {
	public function getServiceUserList($order="accesstime", $orderBy="desc", $start = 0, $limit = 25,$nickname=null) {
		//得到用户——标签对应列表  
		$retVal = Session::init();
		if (!$retVal) {
			Output::instance()->resultCode(code_access_denied);
			return;
		}
		
		$cid = Session::$user["customerId"];
		$material = M("material");
		$arr=$material->where("module='transferCustomerService'")->find();
		//echo 'asdf'.$arr;
		//var_dump($arr);
		if(!isset($arr)){			
			$sql="INSERT INTO `wx_".$cid."_material` (`name`, `module`, `xml`, `groupId`, `updateTime`, `deleted`, `accessTag`) VALUES ('多客服设置', 'transferCustomerService', '<xml><notservicemsg><![CDATA[非人工客服时间]]></notservicemsg><servicesuccessmsg><![CDATA[您已成功转入多客服！]]></servicesuccessmsg><defaultservice><![CDATA[0]]></defaultservice><servicekeyword><![CDATA[kf]]></servicekeyword><endtime><![CDATA[19:30]]></endtime><starttime><![CDATA[9:00]]></starttime><openservice><![CDATA[0]]></openservice></xml>', '0', '2014-08-11 11:22:35', '0', NULL);
			";
			$material->query($sql);				
		}
		$serviceaccesstime = M("module_service_accesstime");
		if($nickname){
			$where=' and nickname like "%'.$nickname.'%"';
		}else{
			$where='';
		}
		$arr=$serviceaccesstime->alias('accesstime')
		->join("JOIN wx_".$cid."_module_service_userinfo  userinfo ON userinfo.openid = accesstime.openid".$where)
		->order("$order $orderBy")
		->limit("$start, $limit")->select();

		$count=$serviceaccesstime->alias('accesstime')
		->join("JOIN wx_".$cid."_module_service_userinfo  userinfo ON userinfo.openid = accesstime.openid".$where)
		->order("$order $orderBy")
		->limit("$start, $limit")->count();
		//echo $serviceaccesstime->getLastSql();
		Output::instance()->objArray($arr, $count);
	
		
	}



	
}